package day0302;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    //通过迭代器和新循环遍历集合
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("12");
        list.add("13");
        list.add("14");
        list.add("15");
        System.out.println("list:"+list);
        Iterator it=list.iterator();

     while (it.hasNext()){
          String str =(String) it.next();
          System.out.println(str);
         }

        for (String a:list){
            String str =(String) a;
            System.out.println(str);
        }
    }
}
